package org.whuims.pois.report;

import org.joda.time.DateTime;
import org.whuims.pois.hibernate.BaseDao;
import org.whuims.pois.model.DataC;
import org.whuims.pois.model.View;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by john on 2015/5/21.
 */
public class LoadFromDB {

    static BaseDao baseDao = new BaseDao();

    public static List<DataC> loadDataC(Timestamp start, Timestamp end, long topicId) {
        if (start.getTime() > end.getTime())
            return new ArrayList<DataC>();
        List<DataC> result = baseDao.findByParamsArr("from DataC where newstime > ? and newstime < ? and topicid = ?", start, end, topicId);
        return result;
    }

    public static List<DataC> loadDataC(Timestamp start, Timestamp end, int topicId, String type) {
        if (start.getTime() > end.getTime())
            return new ArrayList<DataC>();
        List<DataC> result = baseDao.findByParamsArr("from DataC where newtime > ? and newstime < ? and topicid = ? and type = ?", start, end, topicId, type);
        return result;
    }

    public static List<View> loadView(int dayShift, int topicId) {
        DateTime dateTime = new DateTime();
        Timestamp end = new Timestamp(dateTime.getMillis());
        Timestamp start = new Timestamp(dateTime.minusDays(dayShift).getMillis());
        List<View> views = baseDao.findByParamsArr("from View where time > ? and time < ? and topicId = ?", start, end, topicId);
        if (views.size() > 0)
            return views;
        else return new ArrayList<View>();
    }
}
